from django.utils.deprecation import MiddlewareMixin

from utils import restful, status

EXCLUDE_URL = [
    '/auth/login/',
    '/occupation/getUserConnection/',
    '/occupation/bindingUser/',
    '/occupation/registerUser/',
    '/occupation/getQuestionList/',
    '/admin/allUserInfo/',
    '/admin/updateUserInfo/',
    '/admin/resetPassword/'
]


class AuthenticationMiddleware(MiddlewareMixin):

    def process_request(self, request):
        if request.path in EXCLUDE_URL:
            return None
        else:
            data = status.status(request)
            if data:
                return None
            else:
                return restful.unauth(message='身份验证失败，请重新登录！')
